import Vue from 'vue'
import VueRouter from 'vue-router'

import login from "@/components/login";
import role from "@/components/role";
import Main from "../components/Main";
import account from "../components/account";
import bugDistribution from "../components/bugDistribution";
import bugHandle from "../components/bugHandle";
import buglist from "../components/buglist";
import bugtype from "../components/bugtype";
import ClassificationProportion from "../components/ClassificationProportion";
import daily from "../components/daily";
import feedBack from "../components/feedBack";
import member from "../components/member";
import priority from "../components/priority";
import project from "../components/project";
import rule from "../components/rule";
import savarity from "../components/savarity";
import severityDistribution from "../components/severityDistribution";
import StateDistribution from "../components/StateDistribution";
import monthly from "../components/monthly"
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: login
  },
  {
    path: '/main',
    name: 'Main',
    component: Main,
    children:[
      {
        path: '/main/account',
        name: 'account',
        component: account,
      },
      {
        path: '/main/bugDistribution',
        name: 'bugDistribution',
        component: bugDistribution,
      },
      {
        path: '/main/bugHandle',
        name: 'bugHandle',
        component: bugHandle,
      },
      {
        path: '/main/buglist',
        name: 'buglist',
        component: buglist,
      },
      {
        path: '/main/bugtype',
        name: 'bugtype',
        component: bugtype,
      },
      {
        path: '/main/ClassificationProportion',
        name: 'ClassificationProportion',
        component: ClassificationProportion,
      },
      {
        path: '/main/daily',
        name: 'daily',
        component: daily,
      },
      {
        path: '/main/feedBack',
        name: 'feedBack',
        component: feedBack,
      },
      {
        path: '/main/member',
        name: 'member',
        component: member,
      },

      {
        path: '/main/priority',
        name: 'priority',
        component: priority,
      },
      {
        path: '/main/project',
        name: 'project',
        component: project,
      },
      {
        path: '/main/role',
        name: 'role',
        component: role,
      },
      {
        path: '/main/rule',
        name: 'rule',
        component: rule,
      },
      {
        path: '/main/savarity',
        name: 'savarity',
        component: savarity,
      },
      {
        path: '/main/severityDistribution',
        name: 'severityDistribution',
        component: severityDistribution,
      },
      {
        path: '/main/StateDistribution',
        name: 'StateDistribution',
        component: StateDistribution,
      },
      {
        path: '/main/monthly',
        name: 'monthly',
        component: monthly,
      }
    ]
  },
]
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next) => {
  if(to.path == "/") {
    next();
  } else {
    let account = localStorage.getItem("account");
    if(account == undefined || account == null) {
      router.push("/");
    } else next();
  }
})

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
export default router
